package com.android.lovingpet.adopt.host.hostinfo;

import android.os.Bundle;

import com.android.lovingpet.bean.HostFoster;

import com.android.lovingpet.common.Back;
import com.android.lovingpet.util.CallbackStore;
import com.android.lovingpet.util.MyHttp;
import com.android.lovingpet.util.URLStore;
import com.android.lovingpet.util.Utility;
import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

/**
 * Created by ikata on 2018/5/21.
 */

public class HostInfoModel {

    public void getHostFosterById(int id,Back back)
    {
        MyHttp.getInstance().postAsync(Utility.getJSessionId(), URLStore.HOST_GETHOSTFOSTERBYID,"fosterId", String.valueOf(id),new CallbackStore.CallbackNon<Back>(back)
        {
            @Override
            public void onResponse(String json) {
                try {
                    JSONObject json1=new JSONObject(json);
                    HostFoster hostFoster=new Gson().fromJson(json1.getString("hostFoster"),HostFoster.class);
                    Bundle bundle=new Bundle();
                    bundle.putParcelable("result",hostFoster);
                    back.onSuccess(bundle);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        });
    }
    public void fostersPet(HashMap<String,String> params, Back back)
    {
        MyHttp.getInstance().postAsync(Utility.getJSessionId(), URLStore.HOST_FOSTERSPET, params,new CallbackStore.CallbackNon<Back>(back){
            @Override
            public void onResponse(String json) {
                super.onResponse(json);
            }
        });
    }
    public void updateInfo(HashMap<String,String> params,Back back)
    {
        MyHttp.getInstance().postAsync(Utility.getJSessionId(),URLStore.HOST_UPDATEINFO,params,new CallbackStore.CallbackNon<Back>(back)
        {
            @Override
            public void onResponse(String json) {
                super.onResponse(json);
            }
        });
    }
    public void updateState(HashMap<String,String> params,Back back)
    {
        MyHttp.getInstance().postAsync(Utility.getJSessionId(),URLStore.HOST_UPDATESTATE,params,new CallbackStore.CallbackNon<Back>(back)
        {
            @Override
            public void onResponse(String json) {
                super.onResponse(json);
            }
        });

    }

}
